using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAO;
using System.Data;

namespace BUS
{
    /// <summary> 
    ///Author: daiduong19051986@gmail.com 
    /// <summary>
    public class TVC_LOOKUPControl
    {
        #region Local Variable
        private TVC_LOOKUPDataAccess _objDAO;
        public string business = "HV";
        #endregion Local Variable

        #region Method
        public TVC_LOOKUPControl()
        {
            _objDAO = new TVC_LOOKUPDataAccess();
        }

        public TVC_LOOKUPControl(String bus)
        {
            business = bus;
            _objDAO = new TVC_LOOKUPDataAccess();
        }
        public TVC_LOOKUPInfo Get(string db, String TB, String TBField, String Code, ref string sErr)
        {
            return _objDAO.Get(db, TB, TBField, Code, ref sErr);
        }

        public DataTable GetAll(string db, ref string sErr)
        {
            return _objDAO.GetAll(db, ref sErr);
        }

        public Int32 Add(string db, TVC_LOOKUPInfo obj, ref string sErr)
        {
            return _objDAO.Add(db, obj, ref sErr);
        }

        public string Update(string db, TVC_LOOKUPInfo obj)
        {
            return _objDAO.Update(db, obj);
        }

        public string Delete(string db, String TB, String TBField, String Code)
        {
            return _objDAO.Delete(db, TB, TBField, Code);

        }
        public Boolean IsExist(string db, String TB, String TBField, String Code)
        {
            return _objDAO.IsExist(db, TB, TBField, Code);
        }

        public DataTable Search(string db, String columnName, String columnValue, String condition, String tableName, ref String sErr)
        {
            return _objDAO.Search(db, columnName, columnValue, condition, tableName, ref  sErr);
        }
        public string InsertUpdate(string db, TVC_LOOKUPInfo obj)
        {
            string sErr = "";
            if (_objDAO.IsExist(db, obj.TB, obj.TBField, obj.Code))
            {
                sErr = Update(db, obj);
            }
            else _objDAO.Add(db, obj, ref sErr);
            return sErr;
        }

        public DataTable GetTransferOut(string dtb, object from, object to, ref string sErr)
        {
            return _objDAO.GetTransferOut(dtb, from, to, ref sErr);
        }

        public DataTable ToTransferInStruct()
        {
            return TVC_LOOKUPInfo.ToDataTable();
        }

        public string TransferIn(string db, DataRow row)
        {
            TVC_LOOKUPInfo inf = new TVC_LOOKUPInfo(row);
            return InsertUpdate(db, inf);

        }
        #endregion Method

        /// <summary>
        /// Filter
        /// </summary>
        /// <param name="strFilter"></param>
        /// <param name="sErr"></param>
        /// <returns></returns>
        public DataTable GetSearch(string db, string strFilter, String TBField, ref string sErr)
        {
            return _objDAO.Get(db, strFilter, TBField, ref sErr);

        }

        public DataTable GetbyTBField(string db, string TBField, ref string sErr)
        {
            return _objDAO.Get(db, null, TBField, ref sErr);
        }

        public DataTable GetbycboStatus(string db, String filters, string TBField, ref string sErr)
        {
            return _objDAO.Get(db, filters, TBField, ref sErr);
        }


        public DataTable GetQuery(string query, ref string sErr)
        {
            return _objDAO.GetQuery(query, ref sErr);
        }

        public DataTable GetDescription(string db, string TB, string _MovenmentAccount, string Category, ref string sErr)
        {
            return _objDAO.GetDescription(db, TB, _MovenmentAccount, Category, ref sErr);

        }

        public DataTable GetDepartment(string db, ref string sErr)
        {
            return _objDAO.GetTable(db, "TVC_RFITM", "Department", ref sErr);
        }

        public DataTable GetUnit(string db, ref string sErr)
        {
            return _objDAO.GetTable(db, "TVC_RFITM", "UOM", ref sErr);
        }
    }
}
